<template>
  <div class="shop-cart-list">
    <div
      class="cube-popup cube-popup_mask cube-shop-cart-list"
      v-show="showMask"
    >
      <div class="cube-popup-mask" @click.stop="btnHide"></div>
      <div class="cube-popup-container cube-popup-bottom">
        <div class="cube-popup-content">
          <div>
            <div class="list-header">
              <h1 class="title">购物车</h1>
              <h2 class="empty" @click.stop="btnHide">清空</h2>
            </div>
            <div class="cube-scroll-wrapper list-content">
              <div class="cube-scroll-content">
                <div class="cube-scroll-list-wrapper">
                  <ul>
                    <li class="food" v-for="item of allCons" :key="item.name">
                      <span class="name">{{ item.name }}</span>
                      <div class="price">
                        <span>￥{{ item.price }}</span>
                      </div>
                      <div class="cart-control-wrapper">
                        <div class="cartcontrol">
                          <div class="cart-decrease">
                            <i class="cubeic-remove"></i>
                          </div>
                          <div class="cart-count">{{ item.count }}</div>
                          <div class="cart-add icon-add_circle">
                            <i class="cubeic-add"></i>
                          </div>
                        </div>
                      </div>
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
const BALL_LEN = 10;
const innerClsHook = 'inner-hook';

function createBalls() {
  let balls = [];
  for (let i = 0; i < BALL_LEN; i++) {
    balls.push({ show: false });
  }
  return balls;
}

export default {
  name: 'cartList"',
  props: {
    ret: Array,
    selectFoods: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      freight: 0,
      distribution: 3,
      start: 15,
      num: 0,
      showMask: false,
      allCons: [],
      price: 0,
      balls: createBalls(),
    };
  },
  watch: {
    allCons(news) {
      let numAll = 0,
        price = 0;
      for (let i = 0; i < allCon.length; i++) {
        numAll += allCon[i].count;
        price += allCon[i].price;
      }
      this.num = numAll;
      this.price = price;
    },
  },
  computed: {
    totalCount() {
      let count = 0;
      this.selectFoods.forEach((food) => {
        count += food.count;
      });
      return count;
    },
  },
  methods: {
    btnShow() {
      this.allCons = JSON.parse(sessionStorage.getItem('allCon'));
      this.allCons ? (this.showMask = true) : (this.showMask = false);
    },
    btnHide() {
      this.showMask = false;
    },
    drop(el) {},
  },
};
</script>
<style lang="stylus" scoped>
.cube-shop-cart-list {
  bottom: 48px;
  position: fixed;
  right: 0;
  top: 0;
}


>>>.list-header {
  background: #f3f5f7;
  height: 40px;
  line-height: 40px;
  padding: 0 18px;
  display: flex;
}

>>>.title {
  color: #333;
  flex: 1;
  text-align: left;
  font-size: 14px;
}

>>>.empty {
  color: #00a0dc;
  flex: 1;
  display: inline-block;
  text-align: right;
  font-size: 12px;
}

>>>.list-content {
  background: #fff;
  max-height: 217px;
  overflow: hidden;
  padding: 0 18px;
  height: 100%;
}

>>>.cube-scroll-content {
  position: relative;
  z-index: 1;
}

>>>.food {
  box-sizing: border-box;
  padding: 12px 0;
  position: relative;
  text-align: left;

  .name {
    color: #333;
    font-size: 14px;
    line-height: 24px;
    flex: 1;
    text-align: left;
  }

  .price {
    bottom: 12px;
    color: #f01414;
    flex: 2;
    font-size: 14px;
    font-weight: 700;
    line-height: 24px;
    position: absolute;
    right: 90px;
  }
}

.cart-control-wrapper {
  bottom: 6px;
  position: absolute;
  right: 0;

  >>>.cartcontrol {
    display: flex;
  }

  .cart-count {
    color: #666;
    font-size: 10px;
    line-height: 36px;
    text-align: center;
    width: 12px;
  }

  .cart-add, .cart-decrease {
    color: #00a0dc;
    display: inline-block;
    font-size: 24px;
    line-height: 24px;
    padding: 6px;
  }
}

>>>.cube-scroll-list-wrapper {
  overflow: hidden;
  min-height: 0;
}
</style>
